package com.mallcloud.mall.mall.service.impl;

import com.mallcloud.mall.app.mapper.AppProcedureMapper;
import com.mallcloud.mall.common.core.exception.FailException;
import com.mallcloud.mall.mall.api.entity.dto.ParkingPointsPayDiscount;
import com.mallcloud.mall.mall.api.entity.dto.ProParkingCouponWriteOff;
import com.mallcloud.mall.mall.service.MallParkingCouponService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 停车券管理
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MallParkingCouponServiceImpl implements MallParkingCouponService {
	private final AppProcedureMapper procedureMapper;

	@SneakyThrows
	@Override
	public void parkingCouponWriteOff(ProParkingCouponWriteOff dto) {
		procedureMapper.redeemCouponWriteOff(dto);
		if (!dto.isSuccess()) {
			log.error("失败");
			throw new FailException(dto.getMessage());
		}
	}

	/**
	 * 积分抵扣停车费
	 *
	 * @param dto
	 * @return
	 */
	@SneakyThrows
	@Override
	public void parkingPointsDiscount(ParkingPointsPayDiscount dto) {
		procedureMapper.parkingPointsDiscount(dto);
		if (!dto.isSuccess()) {
			log.error("失败");
			throw new FailException(dto.getMessage());
		}
	}

	/**
	 * 停车券核销冲正
	 *
	 * @param entity
	 * @return
	 */
	@SneakyThrows
	@Override
	public void parkingCouponReversal(ProParkingCouponWriteOff entity) {
		procedureMapper.parkingCouponReversal(entity);
		if (!entity.isSuccess()) {
			log.error("失败");
			throw new FailException(entity.getMessage());
		}
	}

	@SneakyThrows
	@Override
	public void ParkingPointsDiscountReversal(ParkingPointsPayDiscount entity) {
		procedureMapper.ParkingPointsDiscountReversal(entity);
		if (!entity.isSuccess()) {
			log.error("失败");
			throw new FailException(entity.getMessage());
		}
	}
}